Imports System.Data
Imports System.Data.SqlClient
Partial Class Client_frmShippingAddress
    Inherits System.Web.UI.Page
    Dim _UserId As String
    Dim _bo As New Bo
    Dim _ShippingAddressVo As New ShippingAddressVO
    Dim dt As New DataTable
    Dim dt1 As New DataTable
    Dim _CityVo As New CityVo
    Dim _CountryVo As New CountryVo
    Dim _StateVo As New StateVo
    Dim dr As DataRow
    Dim _ShipNo As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _UserId = Session("UserId")
        If _UserId = "" Then
            Response.Redirect("frmLogin.aspx")
        End If
        If Not Page.IsPostBack Then
            Call CountryData()
            _ShippingAddressVo.UserId = _UserId
            dt1 = _bo.getBillDate(_UserId)
            _ShippingAddressVo.BillId = dt1.Rows(0).Item(0).ToString
            _ShippingAddressVo.ShipDate = dt1.Rows(0).Item(1).ToString
            lblUserId.Text = _UserId
            lblBillId.Text = _ShippingAddressVo.BillId
            txtBillDate.Text = _ShippingAddressVo.ShipDate
            dt1 = _bo.getShipNo()
            _ShipNo = dt1.Rows(0).Item(0).ToString
            _ShipNo = (Integer.Parse(_ShipNo) + 1)
            _bo.UpdateShipNo(_ShipNo)
            _ShippingAddressVo.ShipId = ("Sh" & _ShipNo)
            lblShipId.Text = _ShippingAddressVo.ShipId
            dt = _bo.getBillingAddressDetail(lblBillId.Text)

            For Each dr In dt.Rows
                txtFirstName.Text = dr("FirstName").ToString
                txtLastName.Text = dr("LastName").ToString
                txtAddress.Text = dr("Address").ToString
                ddlCountry.SelectedValue = dr("Country").ToString
                Call StateData()
                ddlState.SelectedValue = dr("State").ToString
                Call CityData()
                ddlCity.SelectedValue = dr("City").ToString
                txtPhoneNumber.Text = dr("PhoneNumber").ToString
                txtMobileNumber.Text = dr("MobileNumber").ToString
                txtZipCode.Text = dr("ZipCode").ToString
            Next
        End If
    End Sub
    Sub clearall()
        txtAddress.Text = ""
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtMobileNumber.Text = ""
        txtPhoneNumber.Text = ""
        txtZipCode.Text = ""
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _bo.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _bo.getstate(ddlCountry.SelectedValue)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Sub CityData()
        Dim dtCity As DataTable
        dtCity = _bo.getCity(ddlState.SelectedValue)
        ddlCity.DataSource = dtCity
        ddlCity.DataValueField = dtCity.Columns(2).ToString
        ddlCity.DataTextField = dtCity.Columns(3).ToString
        ddlCity.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        Call StateData()
        Call CityData()
    End Sub
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        Call CityData()
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        'paypal code to be inserted here

        dt = _bo.getBillingAddressDetail(_UserId)
        _ShippingAddressVo.UserId = lblUserId.Text
        _ShippingAddressVo.BillId = lblBillId.Text
        _ShippingAddressVo.ShipId = lblShipId.Text
        _ShippingAddressVo.FirstName = txtFirstName.Text
        _ShippingAddressVo.LastName = txtLastName.Text
        _ShippingAddressVo.Address = txtAddress.Text
        _ShippingAddressVo.MobileNumber = txtMobileNumber.Text
        _ShippingAddressVo.PhoneNumber = txtPhoneNumber.Text
        _ShippingAddressVo.City = ddlCity.SelectedValue.ToString
        _ShippingAddressVo.State = ddlState.SelectedValue.ToString
        _ShippingAddressVo.Country = ddlCountry.SelectedValue.ToString
        _ShippingAddressVo.Zipcode = txtZipCode.Text
        _bo.insertShippingAddress(_ShippingAddressVo)



        Session("UserId") = _UserId
        '_bo.DeleteCartDetail()
        '_bo.DeleteCartMaster()
        'Response.Redirect("frmFeedback.aspx")
        Response.Redirect("frmTransaction.aspx")
    End Sub
    Protected Sub chk_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chk.CheckedChanged
        If chk.Checked = "false" Then
            clearall()
        Else
            dt = _bo.getBillingAddressDetail(_UserId)

            For Each dr In dt.Rows
                txtFirstName.Text = dr("FirstName").ToString
                txtLastName.Text = dr("LastName").ToString
                txtAddress.Text = dr("Address").ToString
                ddlCountry.SelectedValue = dr("Country").ToString
                Call StateData()
                ddlState.SelectedValue = dr("State").ToString
                Call CityData()
                ddlCity.SelectedValue = dr("City").ToString
                txtPhoneNumber.Text = dr("PhoneNumber").ToString
                txtMobileNumber.Text = dr("MobileNumber").ToString
                txtZipCode.Text = dr("ZipCode").ToString
            Next

        End If

    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAddress.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        txtZipCode.Text = ""
    End Sub
End Class
